<template>
  <div>
      <div @click="hide=!hide" class="pointer text-alignCenter">
        <i class="el-icon-plus"></i>
        <span>职能部门意见</span>
      </div>
      <div v-show="hide==true">
        <div>
          <el-form ref="issueIdea" :model="issueIdea" label-width="80px" :rules="rules">
            <el-form-item label="选择领导" prop="leaderId">
              <template>
                <el-select v-model="issueIdea.leaderId" placeholder="选择领导" style="width:100%">
                  <el-option
                    v-for="item in comments.options"
                    :key="item.leaderId"
                    :label="item.label"
                    :value="item.leaderId"
                  ></el-option>
                </el-select>
              </template>
            </el-form-item>
            <el-form-item prop="comment">
              <el-input
                type="textarea"
                :row="1"
                v-model="issueIdea.comment"
                placeholder="领导的意见导入"
                class="margin"
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="flex-text-end">
          <el-button type="primary" @click="toparent('issueIdea')">完成</el-button>
          <el-button @click="resetToparent('issueIdea')">取消</el-button>
        </div>
      </div>
    </div>
</template>

<script>
export default {
  props: ["comments"],
  data() {
    return {
      hide: false,
      //  部门意见数据
      issueIdea: {
        did: this.comments.did,
        name: "部门n",
        leaderId: "",
        comment: ""
      },
      // 表单验证
      rules: {
        leaderId: [
          {
            required: true,
            message: "请选择领导",
            trigger: "change"
          }
        ],
        comment: [
          { required: true, message: "请输入意见", trigger: "blur" },
          { min: 2, message: "长度不能小于2个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    toparent(issueIdea) {
      this.$refs[issueIdea].validate(valid => {
        if (valid) {
         this.$confirm('是否添加此意见', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '添加意见成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
          this.$emit("getchild", this.issueIdea);
          this.$refs[issueIdea].resetFields();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetToparent(issueIdea) {
      this.$refs[issueIdea].resetFields();
      this.hide = false;
    }
  }
};
</script>
<style scoped src="../../../../public/css/permissionsBase.css"></style>


<style scoped>
</style>
